<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSurveysTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('surveys', function (Blueprint $table) {
            $table->increments('id');
			$table->unsignedMediumInteger('shop_id')->default(0)->comment('门店ID');
			$table->unsignedMediumInteger('device_id')->default(0)->comment('设备ID');
			$table->unsignedMediumInteger('user_id')->default(0)->comment('测量人ID');
            $table->unsignedMediumInteger('member_id')->default(0)->comment('成员ID');
			$table->unsignedTinyInteger('hr')->default(0)->comment('心率 bpm');
			$table->unsignedTinyInteger('sbp')->default(0)->comment('收缩压 mmHg');
			$table->unsignedTinyInteger('dbp')->default(0)->comment('舒张压 mmHg');
			$table->unsignedTinyInteger('bo')->default(0)->comment('血氧 %');
			$table->timestamp('surveyed_at')->nullable()->comment('测量时间');
			$table->unsignedSmallInteger('duration')->default(0)->comment('时长 s');
            $table->timestamps();
            $table->index(['device_id', 'user_id', 'member_id'], 'DidUidMid');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('surveys');
    }
}
